SET(CUR_ARCH "aarch64")
# SET(CUR_ARCH "armhf")
# SET(CUR_ARCH "x86_64")
SET(PREFIX /home/sunjie/work)
# SET(PREFIX /home/user/work)

# set(CMAKE_C_COMPILER /home/user/work/lib/gcc-linaro-6.5.0-2018.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc)
# set(CMAKE_CXX_COMPILER /home/user/work/lib/gcc-linaro-6.5.0-2018.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-g++)

SET(CMAKE_C_FLAGS "-O3 -fPIC -ldl -lpthread -lrt -fexceptions -march=armv8-a -mcpu=cortex-a53 -Wreorder -Wunused-parameter -Wall -Wextra -Wunused-parameter -Wl,--copy-dt-needed-entries")
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -std=c++14 -fpermissive -DWITH_OPENSSL -DWITH_DOM -DWITH_NONAMESPACES -Wl,-unresolved-symbols=ignore-in-shared-libs")
#  

SET(UTIL_DIR ${PROJECT_SOURCE_DIR}/../base_util)
SET(STREAM_DIR ${PROJECT_SOURCE_DIR}/../stream)
SET(COMMON_DIR ${PROJECT_SOURCE_DIR}/../common)
SET(RKMODEL_DIR ${PROJECT_SOURCE_DIR}/rockchip)

aux_source_directory(${UTIL_DIR} util_src)

SET(ROCKCHIP_SOURCE
    ${util_src}

    ${COMMON_DIR}/face_tool.cpp
    
    ${STREAM_DIR}/osd_text.cpp
    
    ${RKMODEL_DIR}/../common/processor.cpp
    ${RKMODEL_DIR}/../common/transforms.cpp
    ${RKMODEL_DIR}/../common/visualize.cpp

    ${RKMODEL_DIR}/../base_predictor.cpp
    ${RKMODEL_DIR}/../model_manager.cpp
    ${RKMODEL_DIR}/../infer_demo.cpp
    ${RKMODEL_DIR}/base/rk_predictor.cpp
    ${RKMODEL_DIR}/cls/cls_video.cpp
    ${RKMODEL_DIR}/det/det_predictor.cpp
    ${RKMODEL_DIR}/face/scrfd_predictor.cpp
    ${RKMODEL_DIR}/face/facefeature_predictor.cpp    
    ${RKMODEL_DIR}/ocr/clipper.cpp
    ${RKMODEL_DIR}/ocr/postprocess_op.cpp
    ${RKMODEL_DIR}/ocr/preprocess_op.cpp
    ${RKMODEL_DIR}/ocr/ocr_det.cpp
    ${RKMODEL_DIR}/ocr/ocr_rec.cpp
    ${RKMODEL_DIR}/rkmodel_manager.cpp
    main.rockchip.cpp
)


set(TARGET_NAME model.rockchip)
add_executable(${TARGET_NAME} ${ROCKCHIP_SOURCE})

# include_directories(${PROJECT_SOURCE_DIR}/src)
# include_directories(${CRYPTO_DIR})
include_directories(${PROJECT_SOURCE_DIR})
include_directories(${PROJECT_SOURCE_DIR}/../)
include_directories(${UTIL_DIR})
include_directories(${AUTH_DIR})


SET(RKSDK_PATH ${PREFIX}/lib/rk3588/install.aarch64)
set(RKSDK_LIB
    ${RKSDK_PATH}/lib/librknn_api.so)
include_directories(${RKSDK_PATH}/include)
target_link_libraries(${TARGET_NAME} ${RKSDK_LIB})

# ffmpeg
SET(FFMPEG_PATH ${PREFIX}/lib/ffmpeg_build.${CUR_ARCH})
set(FFMPEG_LIB
    ${FFMPEG_PATH}/lib/libavcodec.so.58
    ${FFMPEG_PATH}/lib/libavformat.so.58
    ${FFMPEG_PATH}/lib/libavutil.so.56
    ${FFMPEG_PATH}/lib/libswresample.so.3
    ${FFMPEG_PATH}/lib/libx264.so.164
)
include_directories(${FFMPEG_PATH}/include)
target_link_libraries(${TARGET_NAME} ${FFMPEG_LIB})

# openssl
SET(OPENSSL_PATH "${PREFIX}/lib/openssl-1.1.1q/install.${CUR_ARCH}")
set(OPENSSL_LIB
    ${OPENSSL_PATH}/lib/libcrypto.so.1.1
    ${OPENSSL_PATH}/lib/libssl.so.1.1
)
include_directories(${OPENSSL_PATH}/include)
target_link_libraries(${TARGET_NAME} ${OPENSSL_LIB})

# freetype
SET(FREE_PATH ${PREFIX}/lib/freetype-2.13.2/install.${CUR_ARCH})
set(FREE_LIB ${FREE_PATH}/lib/libfreetype.so.6.20.1)
include_directories(${FREE_PATH}/include/freetype2)
target_link_libraries(${TARGET_NAME} ${FREE_LIB})

#harfbuzz
SET(HARF_PATH ${PREFIX}/lib/harfbuzz-2.7.2/install.${CUR_ARCH}.ft)
set(HARF_LIB ${HARF_PATH}/lib/libharfbuzz.so.0.20702.0)
include_directories(${HARF_PATH}/include/harfbuzz)
target_link_libraries(${TARGET_NAME} ${HARF_LIB} ${HARF_LIB})

# opencv3.4.5
SET(OPENCV_PATH ${PREFIX}/lib/opencv-3.4.5/install.${CUR_ARCH}.freetype)
set(OPENCV_LIB ${OPENCV_PATH}/lib/libopencv_world.so.3.4)
include_directories(${OPENCV_PATH}/include)
target_link_libraries(${TARGET_NAME} ${OPENCV_LIB})

# boost
SET(BOOST_PATH "${PREFIX}/lib/boost_1_67_0")
set(BOOST_LIB
    ${BOOST_PATH}/stage/lib.${CUR_ARCH}/libboost_filesystem.a
    ${BOOST_PATH}/stage/lib.${CUR_ARCH}/libboost_system.a
    ${BOOST_PATH}/stage/lib.${CUR_ARCH}/libboost_date_time.a
    ${BOOST_PATH}/stage/lib.${CUR_ARCH}/libboost_regex.a
)
include_directories(${BOOST_PATH})
target_link_libraries(${TARGET_NAME} ${BOOST_LIB})

# json
SET(JSONCPP_PATH ${PREFIX}/lib/jsoncpp-1.9.5/install.${CUR_ARCH})
set(JSONCPP_LIB ${JSONCPP_PATH}/lib/libjsoncpp.a)
include_directories(${JSONCPP_PATH}/include)
target_link_libraries(${TARGET_NAME} ${JSONCPP_LIB})

# spdlog
SET(SPDLOG_PATH ${PREFIX}/lib/spdlog-1.9.2/install.${CUR_ARCH})
set(SPDLOG_LIB ${SPDLOG_PATH}/lib/libspdlog.a)
include_directories(${SPDLOG_PATH}/include)
target_link_libraries(${TARGET_NAME} ${SPDLOG_LIB})

# yaml
SET(YAML_PATH ${PREFIX}/lib/yaml-cpp-yaml-cpp-0.6.2/install.${CUR_ARCH})
set(YAML_LIB ${YAML_PATH}/lib/libyaml-cpp.a)
include_directories(${YAML_PATH}/include)
target_link_libraries(${TARGET_NAME} ${YAML_LIB})


target_link_libraries(${TARGET_NAME} ${CMAKE_CXX_FLAGS} ${EXTERNAL_LIB})


# install(DIRECTORY ${MY_BUILD_ROOT}/src/libhbspdev.so
# 	DESTINATION ${MY_OUTPUT_ROOT}/)






# install(TARGETS ${HBSPDEV_NAME} DESTINATION ${MY_OUTPUT_ROOT})
# install(TARGETS ${SRCAMPY_NAME} DESTINATION ${MY_OUTPUT_ROOT})
# install(TARGETS ${SPCDEV_NAME} DESTINATION ${MY_OUTPUT_ROOT})
